<?php

namespace app\adminapi\controller;

use think\Controller;

class BaseApi extends Controller
{
    public function _initialize(){
        parent::_initialize();
        header("Access-Control-Allow-Origin:*");
        header("Access-Control-Allow-Methods:GET,POST,PUT,DELETE,OPTIONS,PATCH");
        header("Access-Control-Allow-Headers:x-requested-with,content-type,Authorization,X-Requested-With,Content-Type,Accept,Origin");

    }
    // 通用响应
    public function response($code = 200,$msg = 'success',$data = []){
        $res = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ];
        echo json_encode($res,JSON_UNESCAPED_UNICODE);die;
    }
    // 失败时候相应
     public function fail($code =500,$msg ='fail',$data = []){
        $res = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ];
        echo json_encode($res,JSON_UNESCAPED_UNICODE);die;
    }
}
